package com.buer.storage.api;


import com.buer.storage.business.dto.PutStorageAllDto;
import com.buer.storage.business.dto.PutStorageDto;
import com.buer.storage.business.dto.WorderDto;
import com.buer.storage.business.service.WorderService;
import com.buer.storage.common.annotation.Auth;
import com.buer.storage.common.eumn.ResultEnum;
import com.buer.storage.common.utils.BaseResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/put")
public class WorderController {
    @Resource
    private WorderService worderService;

    //增加入库信息
    @Auth
    @PostMapping("/insertPutStorage.do")
    public BaseResult insert(@RequestBody PutStorageDto putStorageDto) {
        //System.out.println(putStorageDto);
        if (worderService.insert(putStorageDto) > 0) {

            //入库单保存成功
            return BaseResult.build(ResultEnum.SUCCESS);
        }
        //入库单保存失败
        return BaseResult.build(ResultEnum.FAILURE);
    }

    //查询所有订单信息
    @Auth
    @GetMapping("/findOrderAll.do")
    public BaseResult findOrderAll() {
        List<WorderDto> orderAll = worderService.findOrderAll();
        return BaseResult.build(ResultEnum.SUCCESS, orderAll);
    }


    //根据入库订单ID删除入库信息
    @Auth
    @GetMapping("/deletePutStorageById.do")
    public BaseResult deletePutStorageById(int putId) {
        if (worderService.deletePutStorageById(putId) > 0) {
            //删除入库单成功
            return BaseResult.build(ResultEnum.SUCCESS);
        }
        return BaseResult.build(ResultEnum.FAILURE);
    }

    //根据商品ID删除商品信息
    @Auth
    @GetMapping("/deleteWorderdetails.do")
    public BaseResult deleteWorderdetails(int detailsId) {
        if (worderService.deleteWorderdetails(detailsId) > 0) {
            //删除入库单成功
            return BaseResult.build(ResultEnum.SUCCESS);
        }
        return BaseResult.build(ResultEnum.FAILURE);
    }

    //更新ID删除商品信息
    @Auth
    @PostMapping("/updateWorderdetails.do")
    public BaseResult updateWorderdetails(@RequestBody PutStorageDto putStorageDto) {
        if (worderService.updateWorderdetails(putStorageDto) > 0) {
            //更新入库单成功
            return BaseResult.build(ResultEnum.SUCCESS);
        }
        //更新入库单失败
        return BaseResult.build(ResultEnum.FAILURE);
    }

    //提交商品详情进行累加
    @Auth
    @GetMapping("/submitAddWorderdetails.do")
    public BaseResult submitAddBuerStock(Integer putId) {
        if (worderService.submitAddBuerStock(putId) > 0) {
            //入库存成功
            return BaseResult.build(ResultEnum.SUCCESS);
        }
        //入库存失败
        return BaseResult.build(ResultEnum.FAILURE);
    }

    //根据订单ID查询入库信息
    @Auth
    @GetMapping("/findPutAll.do")
    public BaseResult findPutAll(Integer putId) {
        List<PutStorageAllDto> putAll = worderService.findPutAll(putId);
        return BaseResult.build(ResultEnum.SUCCESS,putAll);
    }
}
